<?php
require_once("include.php");
require_once("gstobj.php");
session_start();
include("menu.php");
//authorise("userinput");
(isset($_REQUEST["restart"])) ? $restart = $_REQUEST["restart"] : $restart = "NULL" ;
(isset($_REQUEST["res"])) ? $res = $_REQUEST["res"] : $res = "NULL" ;
(isset($_REQUEST["sub"])) ? $sub = $_REQUEST["sub"] : $sub = "NULL" ;
(isset($_REQUEST["itemid"])) ? $itemid = $_REQUEST["itemid"] : $itemid = "NULL" ;
//unset($_SESSION["GST"]);
if (!(isset($_SESSION["GST"]))) {$obj = new gst();}
$obj=&$_SESSION["GST"] ;

if ($obj->header[2] !== "") {
 // have already read or created an item
 $obj->applyfromrequest();
 if ($sub == "Save" && $obj->valid) {
  if ($obj->writedb()) {
   $obj->confirmfiled();
  } else {
   $obj->showfail();
  }
 } elseif($res=="restart") {
  unset($_SESSION[$obj->gettablename()]);
 } else {
  $obj->showform();
 }
} elseif ($itemid=="") {
 // request to set up a new item
 $obj->createblank();
 $obj->showform();
} elseif ($itemid == "NULL") {
 // First call
 $obj->showchoose();
} else {
 // try reading the specific item
 if ($obj->readdb($itemid)) {
  $obj->showform();
 } else {
  $obj->showchoose();
 } 
}
?>